package com.cz.nongyetongv5.activity;


import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.AssistEnt;
import com.cz.nongyetongv5.bean.AssistEntBean;;
import com.cz.nongyetongv5.bean.City;
import com.cz.nongyetongv5.bean.CityBean;
import com.cz.nongyetongv5.bean.JsonUtil;
import com.cz.nongyetongv5.bean.PopBean;
import com.cz.nongyetongv5.bean.User;

import com.cz.nongyetongv5.fragment.AreaPopEntFragment;
import com.cz.nongyetongv5.fragment.FragmentAdapter;
import com.ronri.common.WaitDialog;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import okhttp3.Call;


public class AssistEntUpdateActivity extends FragmentActivity implements View.OnClickListener {
    private User user;
    private RelativeLayout rl_back;
    private TextView tv_right;
    private TextView tv_year;
    private List<PopBean> years;
    private RecyclerView rv_year;
    private YearAdapter yearAdapter;
    private LinearLayout ll_year;
    private LinearLayout ll_area;
    private TextView tv_area;


    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    //ViewPage选项卡页面集合
    private List<Fragment> mFragments;
    private FragmentAdapter adapter;
    //Tab标题集合
    private List<String> mTitles;
    private RelativeLayout ll_area_pop;
    private TextView tv_confirm;


    private LinearLayout ll_comple;//完成率
    private TextView tv_comple;//完成率

    private WebView web;
    private String url;
    private boolean isOrder = true;
    private String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
    private String code;

    private RecyclerView rv_list;//列表显示模式
    private boolean isWeb = true;
    private String isSort = "asc";
    private List<AssistEnt> assistEnts;
    private ListAdapter listAdapter;
    private String name = "";

    private LinearLayout ll_year_list;


    private LinearLayout ll_alpha;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_assist_ent_update);
        user = (User) getIntent().getSerializableExtra("user");
        code = user.getKnowRegion();
        name = user.getRegion_name();
        mTitles = new ArrayList<>();
        mFragments = new ArrayList<>();
        assistEnts = new ArrayList<>();
        years = new ArrayList<>();
        years.add(new PopBean(Calendar.getInstance().get(Calendar.YEAR) + "年", true));
        years.add(new PopBean((Calendar.getInstance().get(Calendar.YEAR) - 1) + "年", false));
        years.add(new PopBean((Calendar.getInstance().get(Calendar.YEAR) - 2) + "年", false));
        rl_back = findViewById(R.id.rl_back);
        ll_year_list = findViewById(R.id.ll_year_list);
        ll_alpha = findViewById(R.id.ll_alpha);
        rl_back.setOnClickListener(this);
        tv_right = findViewById(R.id.tv_right);
        tv_right.setText("列表");
        tv_right.setOnClickListener(this);
        tv_year = findViewById(R.id.tv_year);
        tv_year.setText(Calendar.getInstance().get(Calendar.YEAR) + "年");
        tv_right.setOnClickListener(this);
        rv_year = findViewById(R.id.rv_year);
        yearAdapter = new YearAdapter();
        rv_year.setLayoutManager(new LinearLayoutManager(AssistEntUpdateActivity.this));
        rv_year.setAdapter(yearAdapter);
        ll_alpha.setOnClickListener(this);
        yearAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (PopBean popupBean : years) {
                    popupBean.setChecked(false);
                }
                years.get(position).setChecked(true);
                adapter.notifyDataSetChanged();
                tv_year.setText(years.get(position).getName());
//                rv_year.setVisibility(View.GONE);
                ll_year_list.setVisibility(View.GONE);
                tv_year.setTextColor(Color.parseColor("#585858"));
                tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                        0, R.drawable.jt_down_black, 0);
                year = years.get(position).getName().substring(0, years.get(position).getName().length() - 1);

                if (isWeb) {
                    url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
                    web.loadUrl(url);
                } else {
                    WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                    getList();
                }
            }
        });
        ll_year = findViewById(R.id.ll_year);
        ll_year.setOnClickListener(this);

        ll_area = findViewById(R.id.ll_area);
        ll_area.setOnClickListener(this);
        tv_area = findViewById(R.id.tv_area);
        tv_area.setText(user.getRegion_name());

        ll_area_pop = findViewById(R.id.ll_area_pop);
        mViewPager = findViewById(R.id.viewpager);
        mTabLayout = findViewById(R.id.tab);
        tv_confirm = findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(this);

        ll_comple = findViewById(R.id.ll_comple);
        ll_comple.setOnClickListener(this);
        tv_comple = findViewById(R.id.tv_comple);


        web = findViewById(R.id.web);
        url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
        initWebView();

        rv_list = findViewById(R.id.rv_list);


        listAdapter = new ListAdapter();
        rv_list.setLayoutManager(new LinearLayoutManager(AssistEntUpdateActivity.this));
        rv_list.setAdapter(listAdapter);
        View notDataView = getLayoutInflater().inflate(R.layout.view_nodata, (ViewGroup) rv_list.getParent(), false);
        listAdapter.setEmptyView(notDataView);
        listAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });

        listAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (view.getId() == R.id.rl_list) {//合计

                    Intent intent = new Intent(AssistEntUpdateActivity.this, AssistEntUserActivity.class);
                    intent.putExtra("user", user);
                    if (position == 0) {
                        intent.putExtra("name", name);
                        intent.putExtra("region_code", code);
                        intent.putExtra("isSanme", 0);
                    } else {
                        if (code.equals(assistEnts.get(position).getRegion_code())) {//本级区域
                            intent.putExtra("isSanme", 1);
                        } else {
                            intent.putExtra("isSanme", 0);
                        }
                        intent.putExtra("name", assistEnts.get(position).getName());
                        intent.putExtra("region_code", assistEnts.get(position).getRegion_code());
                    }
                    intent.putExtra("year", year);
                    startActivity(intent);
                } else if (view.getId() == R.id.ll_count_list) {//生产主体总数
                    if (assistEnts.get(position).getSumCount()==0){
                        Toast.makeText(AssistEntUpdateActivity.this, "没有数据", Toast.LENGTH_SHORT).show();
                    }else {
                        if (code.equals(assistEnts.get(position).getRegion_code())) {//本级区域
                            toTypeCountLIst(position, 0, 1);
                        } else {
                            toTypeCountLIst(position, 0, 0);
                        }
                    }

                } else if (view.getId() == R.id.ll_add_list) {//新增
                    if (assistEnts.get(position).getAddCount()==0){
                        Toast.makeText(AssistEntUpdateActivity.this, "没有数据", Toast.LENGTH_SHORT).show();
                    }else {
                        if (code.equals(assistEnts.get(position).getRegion_code())) {//本机区域
                            toTypeCountLIst(position, 1, 1);
                        } else {
                            toTypeCountLIst(position, 1, 0);
                        }
                    }
                } else if (view.getId() == R.id.ll_update_list) {//更新
                    if (assistEnts.get(position).getUpdateCount()==0){
                        Toast.makeText(AssistEntUpdateActivity.this, "没有数据", Toast.LENGTH_SHORT).show();
                    }else {
                        if (code.equals(assistEnts.get(position).getRegion_code())) {//本机区域
                            toTypeCountLIst(position, 2, 1);
                        } else {
                            toTypeCountLIst(position, 2, 0);
                        }
                    }

                } else if (view.getId() == R.id.ll_del_list) {//注销
                    if (assistEnts.get(position).getCancelCount()==0){
                        Toast.makeText(AssistEntUpdateActivity.this, "没有数据", Toast.LENGTH_SHORT).show();
                    }else {
                        if (code.equals(assistEnts.get(position).getRegion_code())) {//本机区域
                            toTypeCountLIst(position, 3, 1);
                        } else {
                            toTypeCountLIst(position, 3, 0);
                        }
                    }
                }
            }
        });
    }

    /**
     * 跳转至类型列表页面
     *
     * @param position
     * @param type
     */
    private void toTypeCountLIst(int position, int type, int isSame) {
        Intent intent = new Intent(AssistEntUpdateActivity.this, AssistEntListTypeActivity.class);
        if (position == 0) {
            intent.putExtra("region_code", code);
        } else {
            intent.putExtra("region_code", assistEnts.get(position).getRegion_code());
        }
        intent.putExtra("isSame", isSame);
        intent.putExtra("year", year);
        intent.putExtra("type", type);
        startActivity(intent);
    }


    private void initWebView() {
        WebSettings webSettings = web.getSettings();
        //JS
        webSettings.setJavaScriptEnabled(true);
        //支持缩放，默认为true。
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        //不显示webview缩放按钮
        webSettings.setDisplayZoomControls(false);
        //调整图片至适合webview的大小
        //                webSettings.setUseWideViewPort(true);
        // 缩放至屏幕的大小
        webSettings.setLoadWithOverviewMode(true);
        //设置默认编码
        webSettings.setDefaultTextEncodingName("utf-8");
        //设置自动加载图片
        webSettings.setLoadsImagesAutomatically(true);
        web.setHorizontalScrollBarEnabled(false);//水平不显示
        web.setVerticalScrollBarEnabled(false); //垂直不显示
        web.loadUrl(url);
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });

        web.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress >= 90) {
                    WaitDialog.HideDialog();
                } else {
                    WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                }
                super.onProgressChanged(view, newProgress);
            }


        });


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.ll_alpha:
                if (ll_year_list.getVisibility() == View.VISIBLE) {
                    ll_year_list.setVisibility(View.GONE);
                    tv_year.setTextColor(Color.parseColor("#585858"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
                break;
            case R.id.tv_right:
                if (ll_area_pop.getVisibility() == View.VISIBLE) {
                    ll_area_pop.setVisibility(View.GONE);
                    tv_area.setTextColor(Color.parseColor("#585858"));
                    tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
//                if (rv_year.getVisibility() == View.VISIBLE) {
//                    rv_year.setVisibility(View.GONE);
//                }
                if (ll_year_list.getVisibility() == View.VISIBLE) {
                    ll_year_list.setVisibility(View.GONE);
                    tv_year.setTextColor(Color.parseColor("#585858"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }

                if (isWeb) {
                    isWeb = false;
                    tv_right.setText("统计");
                    web.setVisibility(View.GONE);
                    rv_list.setVisibility(View.VISIBLE);
                    WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                    getList();
                } else {
                    isWeb = true;
                    tv_right.setText("列表");
                    web.setVisibility(View.VISIBLE);
                    rv_list.setVisibility(View.GONE);
                    url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
                    web.loadUrl(url);
                }
                break;
            case R.id.tv_confirm:
                for (int i = mFragments.size() - 1; i >= 0; i--) {
                    if (((AreaPopEntFragment) mFragments.get(i)).getSelectCity() != null) {
                        tv_area.setText(((AreaPopEntFragment) mFragments.get(i)).getSelectCity().getName());
                        code = ((AreaPopEntFragment) mFragments.get(i)).getSelectCity().getCode();
                        name = ((AreaPopEntFragment) mFragments.get(i)).getSelectCity().getName();
                        tv_area.setTextColor(Color.parseColor("#585858"));
                        tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                                0, R.drawable.jt_down_black, 0);
                        ll_area_pop.setVisibility(View.GONE);
                        if (isWeb) {
                            url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
                            web.loadUrl(url);
                        } else {
                            WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                            getList();
                        }
                        return;
                    }
                }
                break;
            case R.id.ll_comple:
                if (ll_area_pop.getVisibility() == View.VISIBLE) {
                    ll_area_pop.setVisibility(View.GONE);
                    tv_area.setTextColor(Color.parseColor("#585858"));
                    tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
//                if (rv_year.getVisibility() == View.VISIBLE) {
//                    rv_year.setVisibility(View.GONE);
//                    tv_year.setTextColor(Color.parseColor("#585858"));
//                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
//                            0, R.drawable.jt_down_black, 0);
//                }

                if (ll_year_list.getVisibility() == View.VISIBLE) {
                    ll_year_list.setVisibility(View.GONE);
                    tv_year.setTextColor(Color.parseColor("#585858"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }

                if (isOrder) {//升序
                    isOrder = false;
                    isSort = "desc";
                    tv_comple.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.icon_jt_down, 0);
                    if (web.getVisibility() == View.VISIBLE) {
                        url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
                        web.loadUrl(url);
                    } else {
                        WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                        getList();
                    }

                } else {//降序
                    isOrder = true;
                    isSort = "asc";
                    tv_comple.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.icon_jt_up, 0);
                    if (web.getVisibility() == View.VISIBLE) {
                        url = InitApplication.newUrl + "H5/entStatistics?year=" + year + "&region_code=" + code + "&sort=" + isSort;
                        web.loadUrl(url);
                    } else {
                        WaitDialog.ShowDialog(AssistEntUpdateActivity.this, "数据加载中...");
                        getList();
                    }
                }
                break;
            case R.id.ll_year:
                if (ll_area_pop.getVisibility() == View.VISIBLE) {
                    ll_area_pop.setVisibility(View.GONE);
                    tv_area.setTextColor(Color.parseColor("#585858"));
                    tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
//                if (rv_year.getVisibility() == View.GONE) {
//                    rv_year.setVisibility(View.VISIBLE);
//                    tv_year.setTextColor(Color.parseColor("#21b481"));
//                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
//                            0, R.drawable.jt_up_green, 0);
//                } else {
//                    rv_year.setVisibility(View.GONE);
//                    tv_year.setTextColor(Color.parseColor("#585858"));
//                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
//                            0, R.drawable.jt_down_black, 0);
//                }
                if (ll_year_list.getVisibility() == View.GONE) {
                    ll_year_list.setVisibility(View.VISIBLE);
                    tv_year.setTextColor(Color.parseColor("#21b481"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_up_green, 0);
                } else {
                    ll_year_list.setVisibility(View.GONE);
                    tv_year.setTextColor(Color.parseColor("#585858"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
                break;
            case R.id.ll_area:
//                if (rv_year.getVisibility() == View.VISIBLE) {
//                    rv_year.setVisibility(View.GONE);
//                    tv_year.setTextColor(Color.parseColor("#585858"));
//                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
//                            0, R.drawable.jt_down_black, 0);
//                }
                if (ll_year_list.getVisibility() == View.VISIBLE) {
                    ll_year_list.setVisibility(View.GONE);
                    tv_year.setTextColor(Color.parseColor("#585858"));
                    tv_year.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
                if (ll_area_pop.getVisibility() == View.GONE) {
                    mTitles.clear();
                    mFragments.clear();
                    mTitles.add(user.getRegion_name());
                    List<City> cities = new ArrayList<>();
                    City city = new City();
                    city.setCode(user.getKnowRegion());
                    city.setName(user.getRegion_name());
                    city.setChecked(true);
                    cities.add(city);
                    mFragments.add(AreaPopEntFragment.newInstance(cities));
                    tv_area.setTextColor(Color.parseColor("#21b481"));
                    tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_up_green, 0);

                    if (user.getKnowRegion().length() == 8) {
                        initTablayout();
                    } else {
                        getCity(user.getKnowRegion());
                    }
                } else {
                    ll_area_pop.setVisibility(View.GONE);
                    tv_area.setTextColor(Color.parseColor("#585858"));
                    tv_area.setCompoundDrawablesWithIntrinsicBounds(0,
                            0, R.drawable.jt_down_black, 0);
                }
                break;
            default:
                break;
        }
    }


    public class YearAdapter extends BaseQuickAdapter<PopBean, BaseViewHolder> {
        public YearAdapter() {
            super(R.layout.status_pop_item, years);
        }

        @Override
        protected void convert(BaseViewHolder helper, PopBean item) {
            if (item.isChecked()) {
                helper.setTextColor(R.id.tv_name, Color.parseColor("#21b481"));
            } else {
                helper.setTextColor(R.id.tv_name, Color.parseColor("#585858"));
            }
            helper.setText(R.id.tv_name, item.getName());
        }
    }

    private void initTablayout() {
        ll_area_pop.setVisibility(View.VISIBLE);
        adapter = null;
        adapter = new FragmentAdapter(getSupportFragmentManager(), mFragments, mTitles);
        mViewPager.setAdapter(adapter);//给ViewPager设置适配器
        mTabLayout.setupWithViewPager(mViewPager);//将TabLayout和ViewPager关联起来
        mViewPager.setCurrentItem(mFragments.size() - 1);
        mTabLayout.getTabAt(mFragments.size() - 1).select();
    }

    /**
     * 获取区域
     */
    void getCity(String code) {
        OkHttpUtils
                .get()
                .url(InitApplication.newUrl + "system/regionList.json")
                .addParams("addFrom", "1")
                .addParams("addMark", "android")
                .addParams("region_code", code)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        //                                                Toast.makeText(AssistEntUpdateActivity.this, "请求失败，稍后再试", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(String response, int id) {
//                        System.out.println(response);
                        CityBean cityBeann = JsonUtil.toObject(response, CityBean.class);
                        if (cityBeann.getCode() == 0) {
                            if (cityBeann.getData().size() > 0) {
                                mTitles.add("请选择");
                                mFragments.add(AreaPopEntFragment.newInstance(cityBeann.getData()));
                                initTablayout();
                            } else {
                                initTablayout();
                            }
                        } else {
                            Toast.makeText(AssistEntUpdateActivity.this, "获取数据失败，稍后再试", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

    public void setUpdate(String name, String code) {
        //        ToastUtils.showToast(AreaActivity.this, code + name);
        //        ToastUtils.showToast(AreaActivity.this, mViewPager.getCurrentItem() + name + mTitles.size());
        List<String> tmp = new ArrayList<>();
        List<Fragment> tmpFragments = new ArrayList<>();
        for (int i = 0; i <= mViewPager.getCurrentItem(); i++) {
            tmp.add(mTitles.get(i));
            tmpFragments.add(mFragments.get(i));
        }
        tmp.add(tmp.size() - 1, name);
        tmp.remove(tmp.size() - 1);
        tmp.add("请选择");
        mTitles.clear();
        mTitles.addAll(tmp);
        mFragments.clear();
        mFragments.addAll(tmpFragments);
        //        resultCode = code;
        getCity(code);
    }

    void getList() {
        OkHttpUtils
                .get()
                .url(InitApplication.newUrl + "ent/entStatisticsList.json")
                .addParams("addFrom", "1")
                .addParams("addMark", "android")
                .addParams("region_code", code)
                .addParams("year", year)
                .addParams("sort", isSort)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        WaitDialog.HideDialog();
                        Toast.makeText(AssistEntUpdateActivity.this, "请求失败，稍后再试", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        WaitDialog.HideDialog();
                        System.out.println(response);
                        AssistEntBean assistEntBean = JsonUtil.toObject(response, AssistEntBean.class);
                        if (assistEntBean != null) {
                            if (assistEntBean.getCode().equals("0")) {
                                if (assistEntBean.getData().size() == 1) {
                                    assistEnts.clear();
                                } else {
                                    assistEnts.clear();
                                    for (int i = 0; i < assistEntBean.getData().size(); i++) {
                                        if (i == assistEntBean.getData().size() - 1) {
                                            assistEnts.add(0, assistEntBean.getData().get(i));
                                        } else {
                                            assistEnts.add(assistEntBean.getData().get(i));
                                        }
                                    }
                                }
                                listAdapter.notifyDataSetChanged();
                            } else {
                                Toast.makeText(AssistEntUpdateActivity.this, "获取数据失败，稍后再试", Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                });
    }


    public class ListAdapter extends BaseQuickAdapter<AssistEnt, BaseViewHolder> {
        public ListAdapter() {
            super(R.layout.assist_ent_item, assistEnts);
        }

        @Override
        protected void convert(BaseViewHolder helper, AssistEnt item) {
            if (helper.getLayoutPosition() == 0) {
                helper.setTextColor(R.id.tv_title, Color.parseColor("#ff8c04"));
            } else {
                helper.setTextColor(R.id.tv_title, Color.parseColor("#313131"));
            }
            helper.setText(R.id.tv_title, item.getName());
            helper.setText(R.id.tv_percent, item.getPercent());
            if (item.getSumCount() == 0) {
                helper.setText(R.id.tv_count, "--");
            } else {
                helper.setText(R.id.tv_count, item.getSumCount() + "户");
            }
            if (item.getAddCount() == 0) {
                helper.setText(R.id.tv_add, "--");
            } else {
                helper.setText(R.id.tv_add, item.getAddCount() + "户");
            }
            if (item.getUpdateCount() == 0) {
                helper.setText(R.id.tv_update, "--");
            } else {
                helper.setText(R.id.tv_update, item.getUpdateCount() + "户");
            }
            if (item.getCancelCount() == 0) {
                helper.setText(R.id.tv_del, "--");
            } else {
                helper.setText(R.id.tv_del, item.getCancelCount() + "户");
            }

            helper.addOnClickListener(R.id.rl_list).addOnClickListener(R.id.ll_count_list)
                    .addOnClickListener(R.id.ll_add_list).addOnClickListener(R.id.ll_update_list)
                    .addOnClickListener(R.id.ll_del_list);
        }
    }


}
